
/**
 * @ProjectName: 
 * @Copyright: 2014 lisheng Co., Ltd. All Right Reserved.
 * @address: toughheart@163.com
 * @date: 2014年12月25日 下午1:01:04
 * @Description: 本内容未经本人允许禁止使用、转发.
 */
 
package com.ls.fw.data.bean;

import java.io.Serializable;


/**
 * 
 * @author lisheng
 * @date 2014年12月25日 下午1:01:04
 * @version V1.0 
 */
public class SimplePage  implements Serializable {
	
	
	/**
	 * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
	 */
	
	private static final long serialVersionUID = 1L;
	protected int offset = 0; // 偏移量
	protected int page = 1; // 当前页数
	protected int pageSize  = 10; // 每页显示数量
	protected int totalPage = 0; // 总页数
	protected long allRow = 0L; // 总记录数
	
	/**起始行*/
	protected int startRow = 1;
    /**末行*/
	protected int endRow = 1;
    
    
	public SimplePage() {
		super();
	}
	public SimplePage(int offset, int page, int pageSize, int startRow,
			int endRow) {
		super();
		this.offset = offset;
		this.page = page;
		this.pageSize = pageSize;
		this.startRow = startRow;
		this.endRow = endRow;
	}
	

    public SimplePage(int page, int pageSize) {
		super();
		this.page = page;
		this.pageSize = pageSize;
		this.calculateStartAndEndRow();
	}
    
    
	public SimplePage(int offset, int page, int pageSize) {
		this(offset, pageSize, pageSize, offset, offset+pageSize);
	}
    
    
	/**
     * 计算起止行号
     */
    protected void calculateStartAndEndRow() {
        this.startRow = this.page > 0 ? (this.page - 1) * this.pageSize : 0;
        this.offset = this.startRow;
        this.endRow = this.startRow + this.pageSize * (this.page > 0 ? 1 : 0);
    }
    
    public long getAllRow() {
		return allRow;
	}

	public void setAllRow(long allRow) {
		this.allRow = allRow;
        if (pageSize > 0) {
            totalPage = (int) (allRow / pageSize + ((allRow % pageSize == 0) ? 0 : 1));
        } else {
        	totalPage = 0;
        }
        //分页合理化，针对不合理的页码自动处理
        if (page > totalPage) {
            page = totalPage;
            calculateStartAndEndRow();
        }
	}
	public int getOffset() {
		return this.offset;
	}
	public void setOffset(int offset) {
		this.startRow = offset;
		this.offset = offset;
	}
	public int getPage() {
		return this.page;
	}
	public void setPage(int page) {
		//分页合理化，针对不合理的页码自动处理
        this.page = (page <= 0) ? 1 : page;
	}
	public int getPageSize() {
		return this.pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getStartRow() {
		return this.startRow;
	}
	public void setStartRow(int startRow) {
		this.offset = startRow;
		this.startRow = startRow;
	}
	public int getEndRow() {
		return this.endRow;
	}
	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}
	
	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	@Override
	public String toString() {
		return "SimplePage [offset=" + this.offset + ", page=" + this.page
				+ ", pageSize=" + this.pageSize + ", totalPage="
				+ this.totalPage + ", allRow=" + this.allRow + ", startRow="
				+ this.startRow + ", endRow=" + this.endRow + "]";
	}

	
}
